package com.cby.android.sample.adapter

import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.cby.android.library.ext.load
import com.cby.android.sample.R
import com.cby.android.sample.bean.roll.RollNewsInfoBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @description: RollNewsAdapter
 *
 * @author ChenBaoyang
 * @date 4/29/21 10:44
 */
class RollNewsAdapter : BaseQuickAdapter<RollNewsInfoBean, BaseViewHolder>(R.layout.roll_item_news), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: RollNewsInfoBean) {
        item.run {
            holder.setText(R.id.tv_title, title)
            if(TextUtils.isEmpty(digest)) {
                holder.setVisible(R.id.tv_digest, false)
            }else{
                holder.setVisible(R.id.tv_digest, true)
                holder.setText(R.id.tv_digest, digest)
            }

            val image01 = holder.getView<ImageView>(R.id.iv_01)
            val image02 = holder.getView<ImageView>(R.id.iv_02)
            val image03 = holder.getView<ImageView>(R.id.iv_03)
            if (imgList.isNullOrEmpty()) {
                holder.setVisible(R.id.ll_image, false)
            } else {
                holder.setVisible(R.id.ll_image, true)

                when {
                    imgList.size > 3 -> {
                        image01.load(imgList[0],R.drawable.pic_gray_bg)
                        image02.load(imgList[1],R.drawable.pic_gray_bg)
                        image03.load(imgList[2],R.drawable.pic_gray_bg)
                    }
                    imgList.size > 2 -> {
                        image01.load(imgList[0],R.drawable.pic_gray_bg)
                        image02.load(imgList[1],R.drawable.pic_gray_bg)
                    }
                    else -> {
                        image01.load(imgList[0],R.drawable.pic_gray_bg)
                    }
                }

            }

            holder.setText(R.id.tv_source, source)
            holder.setText(R.id.tv_time, postTime)
        }
    }


}